package applications.studentApplicationForm.ui.lib;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridLayout;

import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SpringLayout;
import javax.swing.SwingConstants;

import ontocompo.lib.SpringUtilities;

import org.objectweb.fractal.fraclet.annotations.Component;
import org.objectweb.fractal.fraclet.annotations.Interface;
import org.objectweb.fractal.fraclet.annotations.Requires;

import applications.studentApplicationForm.fc.api.StudentForm;

@Component(provides = {@Interface(name = "jPanelItf", signature = org.objectweb.fractal.swing.JPanelItf.class), @Interface(name = "observer", signature = java.util.Observer.class), @Interface(name = "jPanelAttributes", signature = org.objectweb.fractal.swing.JPanelAttributes.class), @Interface(name = "uicontainerservice", signature = ontocompo.api.UIContainerService.class), @Interface(name = "ontocompointrospection", signature = ontocompo.api.OntoCompoIntrospection.class)})

public class StudentApplicationFormStudentAdressButton extends JPanel implements java.util.Observer, org.objectweb.fractal.swing.JPanelItf, org.objectweb.fractal.swing.JPanelAttributes, ontocompo.api.UIContainerService, ontocompo.api.OntoCompoIntrospection {
	
	private String uid;
	private org.objectweb.fractal.api.Component c;
	
	
	@Requires(name = "studentapplicationFormAdressLabel")
	private ontocompo.api.UIContainerService studentapplicationFormAdressLabel;
	
	@Requires(name = "studentapplicationFormAdressValue")
	private ontocompo.api.UIContainerService studentapplicationFormAdressValue;
	
	
	
	
	@Requires(name = "studentapplicationFormZipCodeLabel")
	private ontocompo.api.UIContainerService studentapplicationFormZipCodeLabel;
	
	@Requires(name = "studentapplicationFormZipCodeValue")
	private ontocompo.api.UIContainerService studentapplicationFormZipCodeValue;
	
	
	
	@Requires(name = "studentapplicationFormCountryLabel")
	private ontocompo.api.UIContainerService studentapplicationFormCountryLabel;
	
	@Requires(name = "studentapplicationFormCountryValue")
	private ontocompo.api.UIContainerService studentapplicationFormCountryValue;
	
	
	
	
	@Requires(name = "studentapplicationFormTelephoneLabel")
	private ontocompo.api.UIContainerService studentapplicationFormTelephoneLabel;
	
	@Requires(name = "studentapplicationFormTelephoneValue")
	private ontocompo.api.UIContainerService studentapplicationFormTelephoneValue;
	
	
	
	
	
	@Requires(name = "studentformdirectoryservice")
	private applications.studentApplicationForm.fc.api.StudentFormDirectoryService studentformdirectoryservice;

	@Requires(name = "studentformdirectoryobservable")
	private ontocompo.api.Observable studentformdirectoryobservable;
	
	
	
	
	
	public StudentApplicationFormStudentAdressButton() {
		super();
		this.uid = "applications.studentApplicationForm.ui.lib.StudentApplicationFormStudentAdressButton";
		System.out.println(this.toString() + " created");
	}



	@Override
	public void init() {
		// TODO Auto-generated method stub
		
		this.studentformdirectoryobservable.addObserver(this);

		this.studentapplicationFormAdressLabel.init();
		this.studentapplicationFormAdressValue.init();
		
		this.studentapplicationFormZipCodeLabel.init();
		this.studentapplicationFormZipCodeValue.init();
		
		
		this.studentapplicationFormCountryLabel.init();
		this.studentapplicationFormCountryValue.init();
		
		
		this.studentapplicationFormTelephoneLabel.init();
		this.studentapplicationFormTelephoneValue.init();
		
		
		this.setBackground(Color.white);

		
		JPanel panel = new JPanel(new GridLayout(4,2,20,20));
		panel.setBackground(Color.white);


		panel.add(this.studentapplicationFormAdressLabel.getComponentItSelf());
		panel.add(this.studentapplicationFormAdressValue.getComponentItSelf());
		
		panel.add(this.studentapplicationFormZipCodeLabel.getComponentItSelf());
		panel.add(this.studentapplicationFormZipCodeValue.getComponentItSelf());
		
		
		panel.add(this.studentapplicationFormCountryLabel.getComponentItSelf());
		panel.add(this.studentapplicationFormCountryValue.getComponentItSelf());
		
		
		panel.add(this.studentapplicationFormTelephoneLabel.getComponentItSelf());
		panel.add(this.studentapplicationFormTelephoneValue.getComponentItSelf());
		
		
		this.add(panel, BorderLayout.WEST);
		
	}
	
	protected JLabel createTd(String txt)
	{
		JLabel result = new JLabel(txt);
		result.setFont(result.getFont().deriveFont(Font.PLAIN));
		result.setHorizontalAlignment(SwingConstants.LEFT);

		return result;
	}
	
	protected JPanel createBox(int thickness)
	{
		JPanel result = new JPanel();
		if (thickness > 0) result.setBorder(BorderFactory.createLineBorder(Color.black, thickness));
		result.setBackground(Color.white);
		return result;
	}

	

	@Override
	public JComponent getComponentItSelf() {
		// TODO Auto-generated method stub
		return this;
	}
	
	

	@Override
	public void update(Object o) {
		// TODO Auto-generated method stub
		
		StudentForm student = this.studentformdirectoryservice.getStudentForm();

		this.setBackground(Color.white);
		this.removeAll();
		
		JPanel panel = new JPanel(new GridLayout(4,2,20,20));
		panel.setBackground(Color.white);
		
		
		if (student != null)
		{
			this.setBackground(Color.white);
			this.removeAll();

			this.studentapplicationFormAdressValue.update(student.getAdress().getAdress());
			this.studentapplicationFormZipCodeValue.update(student.getAdress().getZipCode());
			this.studentapplicationFormCountryValue.update(student.getAdress().getCountry());
			this.studentapplicationFormTelephoneValue.update(student.getAdress().getTelephone());
			
			panel.add(this.studentapplicationFormAdressLabel.getComponentItSelf());
			panel.add(this.studentapplicationFormAdressValue.getComponentItSelf());
			
			panel.add(this.studentapplicationFormZipCodeLabel.getComponentItSelf());
			panel.add(this.studentapplicationFormZipCodeValue.getComponentItSelf());
			
			panel.add(this.studentapplicationFormCountryLabel.getComponentItSelf());
			panel.add(this.studentapplicationFormCountryValue.getComponentItSelf());
			
			
			panel.add(this.studentapplicationFormTelephoneLabel.getComponentItSelf());
			panel.add(this.studentapplicationFormTelephoneValue.getComponentItSelf());
			
			
			
			this.add(panel, BorderLayout.WEST);	

			
			this.getParent().validate();  // pour rafraichir la page

			
		}
		
		
		
	}
	
	public String toString() {
		return "StudentApplicationFormStudentAdressButton";
	}

	

	@Override
	public org.objectweb.fractal.api.Component getFractalComponent() {
		// TODO Auto-generated method stub
		return this.c;
	}

	@Override
	public String getUid() {
		// TODO Auto-generated method stub
		return this.uid;
	}

	@Override
	public void setFractalComponent(org.objectweb.fractal.api.Component c) {
		// TODO Auto-generated method stub
		this.c = c;
	}

	@Override
	public void setUid(String uid) {
		// TODO Auto-generated method stub
		this.uid = uid;
	}



	@Override
	public void update(java.util.Observable o, Object arg) {
		// TODO Auto-generated method stub
		StudentForm bk = this.studentformdirectoryservice.getStudentForm();

		if (bk == null){
			return;
		}
		else { 
			
			this.update(bk);
		}


		
	}
	
	
	

}
